package com.marktotop.controller.business;


import com.marktotop.entity.business.ObserveRecord;
import com.marktotop.entity.business.Supplier;
import com.marktotop.error.SystemException;
import com.marktotop.response.ResultBean;
import com.marktotop.service.IObserveRecordService;
import com.marktotop.vo.business.ObserveVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.Observable;

/**
 * <p>
 *  前端控制器 - 接种后留观记录
 * </p>
 *
 * @author MarkToTop
 * @since 2021-07-12
 */
@Api(tags = "业务模块-接种后留观接口")
@RestController
@RequestMapping("/business/observe")
public class ObserveRecordController {

    @Autowired
    private IObserveRecordService observeService;


    /**
     * 所有接种后留观列表
     *
     * @return
     */
    @ApiOperation(value = "留观列表", notes = "所有接种后留观列表")
    @RequestMapping(value = "/findList",method = RequestMethod.GET)
    @RequiresPermissions({"observe:show"})
    public ResultBean findObserveList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                      @RequestParam(value = "pageSize") Integer pageSize,
                                      ObserveVO observeVO ){
        return observeService.findObserveList(pageNum, pageSize,observeVO);
    }


    /**
     * 根据接种id查询某一留观列表
     *
     * @return
     */
    @ApiOperation(value = "查看某一留观信息", notes = "根据接种id查询某一留观列表")
    @RequestMapping(value = "/get/{id}",method = RequestMethod.GET)
    @RequiresPermissions({"observe:edit"})
    public ResultBean getOneObserveInfo(@PathVariable Long id) throws SystemException {
        ObserveVO oneObserve = observeService.findOneObserve(id);
        if (null == oneObserve){
            return ResultBean.error().message("没有找到相关的接种信息，请核实后重试！");
        }
        return ResultBean.ok().data("result",oneObserve).message("获取对应的接种信息成功！");
    }


    /**
     * 提交留观信息，进行留观记录
     *
     * @param observeRecord
     * @return
     * @throws SystemException
     */
    @ApiOperation(value = "提交留观信息", notes = "提交留观信息，进行留观记录")
    @RequestMapping(value = "/postFrom",method = RequestMethod.POST)
    @RequiresPermissions({"observe:add"})
    public ResultBean postObserveRecord(@RequestBody ObserveRecord observeRecord) throws SystemException, ParseException {
        if (!observeService.postObserveRecord(observeRecord)){
            return ResultBean.error().message("记录留观信息失败，请稍后重试!");
        }
        return ResultBean.ok().message("记录留观信息成功，已完成本次疫苗接种!");
    }
}
